<!DOCTYPE html>
<html lang="en">
<head>
    <meta charset="UTF-8">
    <meta http-equiv="X-UA-Compatible" content="IE=edge">
    <meta name="viewport" content="width=device-width, initial-scale=1.0">
    <title>计算你所能获取的最大利润</title>
</head>
<body>
    <script>
        function maxProfit(arr) {
            var max = 0;
            for (var i = 0 ; i <= arr.length - 2 ; i++) { 
                var j = i + 1;
                while(j < arr.length){
                    if (arr[j] - arr[i] > max) {
                        max = arr[j] - arr[i]
                    }
                    j++;
                }
            }
            return max
        }
        console.log(maxProfit([7, 1, 5, 3, 6, 4]))
    </script>
</body>
</html>